package com.mhb.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mhb.domain.Employee;
import com.mhb.service.EmployeeService;

/**
 * Servlet implementation class UpdateEmployeeServlet
 */
@WebServlet("/UpdateEmployeeServlet")
public class UpdateEmployeeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		System.out.println("update");
		String username=request.getParameter("username");
		String sex=	request.getParameter("sex");
		String age=	request.getParameter("age");
		String 	dapartment=request.getParameter("dapartment");
		String type=request.getParameter("type");
		String year=request.getParameter("year");
		String  id=request.getParameter("id");
		Employee employee=new Employee();
		
		employee.setName(username);
		employee.setSex(sex);
		employee.setAge(age);
		employee.setDapartment(dapartment);
		employee.setType(type);
		employee.setYear(year);
		employee.setId(Integer.valueOf(id));
		EmployeeService employeeService=new EmployeeService();
		try {
			employeeService.updateEmployee(employee);
			List<Employee> employeeList = employeeService.getEmployee();
			request.setAttribute("employeeList", employeeList);
			request.getRequestDispatcher("/main.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}



}
